#include <iostream>
#include <vector>

using namespace std;
class Solution
{
public:
    vector<int> leftRigthDifference(vector<int> &nums)
    {
        int n = nums.size();
        vector<int> answer(n);
        for (int i = 1; i < n; i++)
        { // 前缀和
            nums[i] += nums[i - 1];
        }
        for (int i = 0; i < n; i++)
        {
            if (i == 0)
            {
                answer[0] = nums[n - 1] - nums[0];
            }
            else
            {
                // abs(nums[i - 1] - (nums[n - 1] - nums[i]))
                answer[i] = abs(nums[i - 1] - nums[n - 1] + nums[i]);
            }
        }
        return answer;
    }
};
int main()
{
    Solution s;
    vector<int> nums = {10, 4, 8, 3};
    vector<int> answer = s.leftRigthDifference(nums);
    for (int i = 0; i < answer.size(); i++)
    {
        cout << answer[i] << " ";
    }
    cout << endl;
    return 0;
}
